/////////////////////////////////////////////////page_carRentalOrderDetails//////////////////
$(document).on("pageInit", "#page_carRentalOrderDetails", function(e, pageId, $page) {
    my.givetitle('车辆出租订单详细');
	              $('.CROD-xc-toggle').click(function(){
						 $('.CROD-xc').toggle()
			      })
      			 //车时详情开始
      			    key=my.get_key(my.getCookie('token'))
      			    $.showPreloader()
      			    var car_start //车时开始时间
                    var car_end //车时结束时间
                    var store_id //门店编号
                    var user_id //用户编号
                    var cars_id //车辆编号
                    var info_carRentalOrderDetails={cartime_id:sessionStorage.cartime_id}
                        info_carRentalOrderDetails=my.cryptoASEencrypt(JSON.stringify(info_carRentalOrderDetails),key)

      				$.ajax({
      					url:api.listcartimeinfo,
      					type: 'post',
      					async:false,
      					data:{
      						'api_value':info_carRentalOrderDetails
      					},
      					error:function(){
      						    $.hidePreloader()
      							$.toast("车时详情获取失败");
      						},
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{

      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    console.log(data)
      								    car_start=data.info.cartime_start.substr(0,16) //车时开始时间
                                        car_end=data.info.cartime_end.substr(0,16)//车时结束时间
                                        store_id=data.info.parking_place //门店编号
                                        user_id=data.info.user_id //用户编号
                                        cars_id=data.info.usercar_id //车辆编号
                                        if(data.info.change_state==0){
                                        	$('.xgcs-carRentalOrder').hide()
                                        }else if(data.info.change_state==1){
                                        	$('.xgcs-carRentalOrder').show()
                                        }
                                        if(data.info.cancel_state==0){
                                        	$('.qxcs-carRentalOrder').hide()
                                        }else if(data.info.cancel_state==1){
                                        	$('.qxcs-carRentalOrder').show()
                                        }
                                        $('.usercar_nickname').text(data.info.usercar_nickname)
                                        $('.models_name').text(data.info.models_name)
      								    $('.stores_name').text(data.info.stores_name)
      								    $('.cartime_start').text(data.info.cartime_start)
      								    $('.cartime_end').text(data.info.cartime_end)
      								    //循环输出定单开始
      								    if(data.order_count!=0){
      								    	 $('.carRentalOrderList').empty()
      								      for(var i=0;i<data.order_list.length;i++){
      								    	var list='<div class="CROD-yc CROD-yc-head carRentalOrderList-head " style=" margin-bottom:0"><span>'+config.danwei+data.order_list[i].order_income+'</span><a>'
      								    	         +data.order_list[i].state_dec+'</a><div class="clear"></div></div><div class="CROD-yc-head-main carRentalOrderList-main" >'
		 	                                         +'<div class="CROD-yc"><a>开始时间</a><span class="rent_begin_time">'+data.order_list[i].rent_begin_time.substr(0,16)+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>结束时间</a><span class="rent_end_time">'+data.order_list[i].rent_end_time.substr(0,16)+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>定单金额</a><span class="order_income">'+config.danwei+data.order_list[i].order_income+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>订单状态</a><span class="state_dec">'+data.order_list[i].state_dec+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>到账收益</a><span class="fact_income">'+data.order_list[i].fact_income+'</span><div class="clear"></div></div>'
//                                                   +'<div class="CROD-yc" id="'+data.order_list[i].order_id+'" style="text-align: center;"><div class="bottn">取消订单</div></div>'
                                                     +'</div>'
                                            $('.carRentalOrderList').prepend(list)
		 	                                }
      								      $('.CROD-yc-head').click(function(){
      	    	   	                            $('.CROD-yc-head-main').not($(this).next('.CROD-yc-head-main')).hide()
						                         $(this).next('.CROD-yc-head-main').toggle()
				                          })
      								    }
      								    //循环输出定单结束
      								    //验车状态开始
      								    if(data.info.givecar_state==1){
      								    	$('.yczt-xskz').show()
      								    	$('.givecar_state').show()

      								    }else if(data.info.givecar_state==0){
      								    	$('.yczt-xskz').hide()
      								    	$('.givecar_state').hide()
      								    }
      								    if(data.info.getcar_state==1){

      								    	$('.getcar_state').show()

      								    }else if(data.info.getcar_state==0){

      								    	$('.getcar_state').hide()
      								    }
      								    //取车验车点击
                                        $('.givecar_state').click(function(){
                    	                       sessionStorage.yctypeCarRental=1
                    	                  // $.router.loadPage("carRentalOrderGiveCar.html");
                                            $.router.load(carRentalOrderGiveCarUrl,true);
                                        })
                                        $('.getcar_state').click(function(){
                    	                       sessionStorage.yctypeCarRental=4
                    	                  // $.router.loadPage("carRentalOrderGetCar.html");
                                            $.router.load(carRentalOrderGetCarUrl,true);
                                         })
      								    //验车状态结束
      						}
      					}
      				})
                      //车时详情结束
                      //修改车时开始
                       if(my.parserDate(car_start)>new Date())
                       {
                       	console.log('可以修改')
                      var cal_start_Y=car_start.substr(0,4)
                      var cal_start_M=car_start.substr(5,2)-1
                      var cal_start_D=car_start.substr(8,2)
                      var cal_start_H=car_start.substr(11,2)
                      var cal_end_Y=car_end.substr(0,4)
                      var cal_end_M=car_end.substr(5,2)-1
                      var cal_end_D=car_end.substr(8,2)
                      var cal_end_H=car_end.substr(11,2)
                      var now=new Date();
                       $(".xgcs-carRentalOrder-start").show()
                       $(".xgcs-carRentalOrder-start").datetimePicker({
                            value: [cal_start_Y,cal_start_M+1, cal_start_D, cal_start_H, '00'],
                             onClose:function(){
                         	   $.confirm('确认修改？', function () {
                        var end=car_end;
                        var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
                        if(reg.test($(".xgcs-carRentalOrder-end").val())){
                        	end=car_end
                        }else{
                        	end=$(".xgcs-carRentalOrder-end").val()
                        }
		               	    var info={
      					       cartime_id:sessionStorage.cartime_id,
      					       car_start:$(".xgcs-carRentalOrder-start").val()+':00',
      					       car_end:end,
      					       store_id:store_id,
      					       user_id:user_id,
      					       cars_id:cars_id
      				           }
		               	         console.log(info)
		                       $.showPreloader()
      				            info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				            $.ajax({
      					url:api.upusercartime,
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':info
      					},
      					error:function(){
      						    $.hidePreloader()
      							$.alert("修改车时失败，请重新修改");
      						},
      				    complete:function(){
      				    	$(".xgcs-carRentalOrder-start").val('修改车时开始时间')
      				    	$(".xgcs-carRentalOrder-end").val('修改车时结束时间')
      				    },
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.alert(JSON.parse(data).err_msg);
      								}
      							}else{
      								    data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    $.alert('修改成功',function(){
      								    	my.reload()
      								    })


      							}
      					}
      				});

                         	   },function(){
                         	          	  $(".xgcs-carRentalOrder-start").val('修改车时开始时间')
      				    	              $(".xgcs-carRentalOrder-end").val('修改车时结束时间')
                         	          }
                         	   )
                         	}
                       })
                       $(".xgcs-carRentalOrder-end").datetimePicker({
                            value: [cal_end_Y,cal_end_M+1, cal_end_D, cal_end_H, '00'],
                            onClose:function(){
                         	   $.confirm('确认修改？', function () {
                         	   	var start=car_start;
                        var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
                        if(reg.test($(".xgcs-carRentalOrder-start").val())){
                        	start=car_start
                        }else{
                        	start=$(".xgcs-carRentalOrder-start").val()
                        }
		               	    var info={
      					       cartime_id:sessionStorage.cartime_id,
      					       car_start:start,
      					       car_end:$(".xgcs-carRentalOrder-end").val()+":00",
      					       store_id:store_id,
      					       user_id:user_id,
      					       cars_id:cars_id
      				           }
		               	         console.log(info)
		                       $.showPreloader()
      				            info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				            $.ajax({
      					url:api.upusercartime,
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':info
      					},
      					error:function(){
      						    $.hidePreloader()
      							$.alert("修改车时失败，请重新修改");
      						},
      				    complete:function(){
      				    	$(".xgcs-carRentalOrder-start").val('修改车时开始时间')
      				    	$(".xgcs-carRentalOrder-end").val('修改车时结束时间')
      				    },
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.alert(JSON.parse(data).err_msg);
      								}
      							}else{
      								    data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    $.alert('修改成功',function(){
      								    	my.reload()
      								    })


      							}
      					}
      				});

                         	   },function(){
                         	          	  $(".xgcs-carRentalOrder-start").val('修改车时开始时间')
      				    	              $(".xgcs-carRentalOrder-end").val('修改车时结束时间')
                         	          }
                         	   )
                         	}
                      });
                       }else{
                       	     console.log('不可以修改')
                       	     $(".xgcs-carRentalOrder-start").hide()
                       	     var cal_end_Y=car_end.substr(0,4)
                             var cal_end_M=car_end.substr(5,2)-1
                             var cal_end_D=car_end.substr(8,2)
                             var cal_end_H=car_end.substr(11,2)
                             $(".xgcs-carRentalOrder-end").datetimePicker({
                                  value: [cal_end_Y,cal_end_M+1, cal_end_D, cal_end_H, '00'],
                                  onClose:function(){
                         	              $.confirm('确认修改？', function () {
                         	              	 var start=car_start
                         	              	 var reg = new RegExp("[\\u4E00-\\u9FFF]+","g");
                        if(reg.test($(".xgcs-carRentalOrder-start").val())){
                        	start=car_start
                        }else{
                        	start=$(".xgcs-carRentalOrder-start").val()
                        }

		               	     var info={
      					     cartime_id:sessionStorage.cartime_id,
      					     car_start:start,
      					     car_end: $(".xgcs-carRentalOrder-end").val()+":00",
      					     store_id:store_id,
      					     user_id:user_id,
      					     cars_id:cars_id
      				       }
		               	   console.log(info)
		            $.showPreloader()
      				info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				$.ajax({
      					url:api.upusercartime,
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':info
      					},
      					complete:function(){
      				    	$(".xgcs-carRentalOrder-start").val('修改车时开始时间')
      				    	$(".xgcs-carRentalOrder-end").val('修改车时结束时间')
      				    },
      					error:function(){
      						    $.hidePreloader()
      							$.alert("修改车时失败，请重新修改");
      						},
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.alert(JSON.parse(data).err_msg);
      								}
      							}else{
      								    data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    $.alert('修改成功',function(){
      								    	my.reload()
      								    })


      							}
      					}
      				});
                         	             },function(){
      				             	$(".xgcs-carRentalOrder-end").val('修改车时结束时间')
                             })
                         	          }
                             })

                       }
                      $(".xgcs-carRentalOrder-start").val('修改车时开始时间')
      				    	$(".xgcs-carRentalOrder-end").val('修改车时结束时间')
                        //修改过车时结束
                           //下拉刷新start
      		    $(document).off('refresh').on('refresh', '.pull-to-refresh-content',function() {
      		    	var info_carRentalOrderDetails={cartime_id:sessionStorage.cartime_id}
                        info_carRentalOrderDetails=my.cryptoASEencrypt(JSON.stringify(info_carRentalOrderDetails),key)

      				$.ajax({
      					url:api.listcartimeinfo,
      					type: 'post',
      					async:false,
      					data:{
      						'api_value':info_carRentalOrderDetails
      					},
      					error:function(){
      						    $.hidePreloader()
      							$.toast("车时详情获取失败");
      						},
      				    complete:function(){
      				    	setTimeout(function(){
      				    		 $.pullToRefreshDone('.pull-to-refresh-content')
      				    	},2000)
      				    },
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){

      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $.toast(JSON.parse(data).err_msg);
      								}
      						}else{

      							        data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    console.log(data)
      								    car_start=data.info.cartime_start //车时开始时间
                                        car_end=data.info.cartime_end//车时结束时间
                                        store_id=data.info.parking_place //门店编号
                                        user_id=data.info.user_id //用户编号
                                        cars_id=data.info.usercar_id //车辆编号
                                        $('.usercar_nickname').text(data.info.usercar_nickname)
                                        $('.models_name').text(data.info.models_name)
      								    $('.stores_name').text(data.info.stores_name)
      								    $('.cartime_start').text(data.info.cartime_start)
      								    $('.cartime_end').text(data.info.cartime_end)
      								    //循环输出定单开始
      								    if(data.order_count!=0){
      								      $('.carRentalOrderList').empty()
      								      for(var i=0;i<data.order_list.length;i++){
      								    	var list='<div class="CROD-yc CROD-yc-head carRentalOrderList-head " style=" margin-bottom:0"><span>RMB: '+data.order_list[i].order_income+'</span><a>'
      								    	         +data.order_list[i].state_dec+'</a><div class="clear"></div></div><div class="CROD-yc-head-main carRentalOrderList-main" >'
		 	                                         +'<div class="CROD-yc"><a>开始时间</a><span class="rent_begin_time">'+data.order_list[i].rent_begin_time+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>结束时间</a><span class="rent_end_time">'+data.order_list[i].rent_end_time+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>定单金额</a><span class="order_income">'+data.order_list[i].order_income+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>订单状态</a><span class="state_dec">'+data.order_list[i].state_dec+'</span><div class="clear"></div></div>'
		 	                                         +'<div class="CROD-yc"><a>到账收益</a><span class="fact_income">'+data.order_list[i].fact_income+'</span><div class="clear"></div></div>'
//                                                   +'<div class="CROD-yc" id="'+data.order_list[i].order_id+'" style="text-align: center;"><div class="bottn">取消订单</div></div>'
                                                     +'</div>'
                                            $('.carRentalOrderList').prepend(list)
		 	                                }
      								      $('.CROD-yc-head').click(function(){
      	    	   	                            $('.CROD-yc-head-main').not($(this).next('.CROD-yc-head-main')).hide()
						                         $(this).next('.CROD-yc-head-main').toggle()
				                          })
      								    }
      								    //循环输出定单结束
      								    //验车状态开始
      								    if(data.info.givecar_state==1){
      								    	$('.yczt-xskz').show()
      								    	$('.givecar_state').show()

      								    }else if(data.info.givecar_state==0){
      								    	$('.yczt-xskz').hide()
      								    	$('.givecar_state').hide()
      								    }
      								    if(data.info.getcar_state==1){

      								    	$('.getcar_state').show()

      								    }else if(data.info.getcar_state==0){

      								    	$('.getcar_state').hide()
      								    }
      								    //取车验车点击
                                        $('.givecar_state').click(function(){
                    	                       sessionStorage.yctypeCarRental=1
                    	                   //$.router.loadPage("carRentalOrderGiveCar.html");
                                            $.router.load(carRentalOrderGiveCarUrl,true);
                                        })
                                        $('.getcar_state').click(function(){
                    	                       sessionStorage.yctypeCarRental=4
                    	                   //$.router.loadPage("carRentalOrderGetCar.html");
                                            $.router.load(carRentalOrderGetCarUrl,true);
                                         })
      								    //验车状态结束
      						}
      					}
      				})
      		    })
      		    //下拉刷新结束
      		    //取消车时开始
      		    $('.qxcs-carRentalOrder').click(function(){
      		    	$('.qxcs-carRentalOrder').addClass('active_btn')
      		    	 var info={
      					cartime_id:sessionStorage.cartime_id,
      					user_id:user_id,
      				}
      		    	console.log(info)
		            $.showPreloader()
      				info=my.cryptoASEencrypt(JSON.stringify(info),key)
      				$.ajax({
      					url:api.usercancelcartime,
      					type: 'post',
      					async:true,
      					data:{
      						'api_value':info
      					},
      					error:function(){
      						    $.hidePreloader()
      						    $('.qxcs-carRentalOrder').removeClass('active_btn')
      							$.toast("取消车时失败");
      						},
      					success:function(data){
      						$.hidePreloader()
      						if(data.match("err_code")!=null){
      							switch(JSON.parse(data).err_code)
      								{
      									case 40003:
      									   my.tokenExpire()
      									   break;
      									default:
      									   $('.qxcs-carRentalOrder').removeClass('active_btn')
      									   $.toast(JSON.parse(data).err_msg);
      								}
      							}else{
      								    data=JSON.parse(data)
      								    data=JSON.parse(my.cryptoASEdencrypt(data.data,key))
      								    $.alert('取消成功',function(){
      								       //$.router.loadPage("carRentalOrder.html");
                                            $.router.load(carRentalOrderUrl,true);
                                        })


      							}
      					}
      				});
      		    })
      		    //取消车时结束
})